﻿using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace LxCore
{
    public abstract class JsObject : JsBase, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler? PropertyChanged;
        protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        public virtual void FromJsonKV(string key, IJsonReader jsReader)
        {
            //Type t = this.GetType();
            //var tp = t.GetProperty(key);
            //if (tp == null) { return; }
            //var obj = tp.GetValue(this);
            //switch (obj)
            //{
            //    case string:
            //        tp.SetValue(this, jsReader.ReadString());
            //        break;
            //    case double:
            //        tp.SetValue(this, jsReader.ReadInt());
            //        break;
            //    case bool:
            //        tp.SetValue(this,jsReader.ReadBool());
            //        break;
            //    case JsObject js:
            //        jsReader.ReadObject(js);
            //        break;
            //    default:
            //        throw new InvalidDataException("FromJson错误");
            //}
            throw new InvalidDataException($"未找到对应的Key：{key}");
        }
        public virtual void ToJsonKV(IJsonWriter jsWriter)
        {
       
        }
    }
}
